<!DOCTYPE HTML>
<html lang="en" >
    <!-- Start book Python数据分析课程讲义 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>Pandas的层级索引 | Python数据分析课程讲义</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        <meta name="author" content="BigCat">
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-tbfed-pagefooter/footer.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../file/part03/3.6.html" />
    
    
    <link rel="prev" href="../../file/part03/3.4.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="3.5"
        data-chapter-title="Pandas的层级索引"
        data-filepath="file/part03/3.5.md"
        data-basepath="../.."
        data-revision="Thu Apr 27 2017 00:50:19 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        传智播客Python学院数据分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="file/part01/1.html">
            
                
                    <a href="../../file/part01/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        一、工作环境准备及数据分析建模理论基础
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="file/part01/1.1.html">
            
                
                    <a href="../../file/part01/1.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        Python 3.x新特性和编码回顾
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="file/part01/1.2.html">
            
                
                    <a href="../../file/part01/1.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        DIKW模型与数据工程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="file/part01/1.3.html">
            
                
                    <a href="../../file/part01/1.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        数据分析建模理论基础
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="file/part02/2.html">
            
                
                    <a href="../../file/part02/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        二、科学计算工具NumPy
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="file/part02/2.1.html">
            
                
                    <a href="../../file/part02/2.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        ndarray的创建与数据类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="file/part02/2.2.html">
            
                
                    <a href="../../file/part02/2.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        ndarray的矩阵处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="file/part02/2.3.html">
            
                
                    <a href="../../file/part02/2.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        ndarray的元素处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="file/part02/2.4.html">
            
                
                    <a href="../../file/part02/2.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        实战案例：2016美国总统大选民意调查统计
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="file/part03/3.html">
            
                
                    <a href="../../file/part03/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        三、数据分析工具Pandas
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="file/part03/3.1.html">
            
                
                    <a href="../../file/part03/3.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        Pandas的数据结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="file/part03/3.2.html">
            
                
                    <a href="../../file/part03/3.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        Pandas的索引操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="file/part03/3.3.html">
            
                
                    <a href="../../file/part03/3.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        Pandas的对齐运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="file/part03/3.4.html">
            
                
                    <a href="../../file/part03/3.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        Pandas的函数应用
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="3.5" data-path="file/part03/3.5.html">
            
                
                    <a href="../../file/part03/3.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        Pandas的层级索引
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="file/part03/3.6.html">
            
                
                    <a href="../../file/part03/3.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        Pandas统计计算和描述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="file/part03/3.7.html">
            
                
                    <a href="../../file/part03/3.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        Pandas分组与聚合
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="file/part03/3.8.html">
            
                
                    <a href="../../file/part03/3.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        数据清洗、合并、转化和重构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="file/part03/3.9.html">
            
                
                    <a href="../../file/part03/3.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        聚类模型 -- K-Means介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="file/part03/3.10.html">
            
                
                    <a href="../../file/part03/3.10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        实战案例：全球食品数据分析
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="file/part04/4.html">
            
                
                    <a href="../../file/part04/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        四、数据可视化工具
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="file/part04/4.1.html">
            
                
                    <a href="../../file/part04/4.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        Matplotlib绘图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="file/part04/4.2.html">
            
                
                    <a href="../../file/part04/4.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        Seaborn绘图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="file/part04/4.3.html">
            
                
                    <a href="../../file/part04/4.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        Bokeh绘图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="file/part04/4.4.html">
            
                
                    <a href="../../file/part04/4.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        实战案例：世界高峰数据可视化
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="file/part06/6.html">
            
                
                    <a href="../../file/part06/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        五、自然语言处理NLTK
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="file/part06/6.1.html">
            
                
                    <a href="../../file/part06/6.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        NLTK与自然语言处理基础
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="file/part06/6.2.html">
            
                
                    <a href="../../file/part06/6.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        jieba分词
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="file/part06/6.3.html">
            
                
                    <a href="../../file/part06/6.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        情感分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="file/part06/6.4.html">
            
                
                    <a href="../../file/part06/6.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        文本相似度和分类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="file/part06/6.6.html">
            
                
                    <a href="../../file/part06/6.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        实战案例：微博情感分析
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >Python数据分析课程讲义</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x5C42;&#x7EA7;&#x7D22;&#x5F15;&#xFF08;hierarchical-indexing&#xFF09;">&#x5C42;&#x7EA7;&#x7D22;&#x5F15;&#xFF08;hierarchical indexing&#xFF09;</h1>
<blockquote>
<p>&#x4E0B;&#x9762;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Series&#xFF0C; &#x5728;&#x8F93;&#x5165;&#x7D22;&#x5F15;Index&#x65F6;&#xFF0C;&#x8F93;&#x5165;&#x4E86;&#x7531;&#x4E24;&#x4E2A;&#x5B50;list&#x7EC4;&#x6210;&#x7684;list&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;&#x5B50;list&#x662F;&#x5916;&#x5C42;&#x7D22;&#x5F15;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;list&#x662F;&#x5185;&#x5C42;&#x7D22;&#x5F15;&#x3002;</p>
</blockquote>
<p>&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

ser_obj = pd.Series(np.random.randn(<span class="hljs-number">12</span>),index=[
                [<span class="hljs-string">&apos;a&apos;</span>, <span class="hljs-string">&apos;a&apos;</span>, <span class="hljs-string">&apos;a&apos;</span>, <span class="hljs-string">&apos;b&apos;</span>, <span class="hljs-string">&apos;b&apos;</span>, <span class="hljs-string">&apos;b&apos;</span>, <span class="hljs-string">&apos;c&apos;</span>, <span class="hljs-string">&apos;c&apos;</span>, <span class="hljs-string">&apos;c&apos;</span>, <span class="hljs-string">&apos;d&apos;</span>, <span class="hljs-string">&apos;d&apos;</span>, <span class="hljs-string">&apos;d&apos;</span>],
                [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>]
            ])
print(ser_obj)
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python">a  <span class="hljs-number">0</span>    <span class="hljs-number">0.099174</span>
   <span class="hljs-number">1</span>   -<span class="hljs-number">0.310414</span>
   <span class="hljs-number">2</span>   -<span class="hljs-number">0.558047</span>
b  <span class="hljs-number">0</span>    <span class="hljs-number">1.742445</span>
   <span class="hljs-number">1</span>    <span class="hljs-number">1.152924</span>
   <span class="hljs-number">2</span>   -<span class="hljs-number">0.725332</span>
c  <span class="hljs-number">0</span>   -<span class="hljs-number">0.150638</span>
   <span class="hljs-number">1</span>    <span class="hljs-number">0.251660</span>
   <span class="hljs-number">2</span>    <span class="hljs-number">0.063387</span>
d  <span class="hljs-number">0</span>    <span class="hljs-number">1.080605</span>
   <span class="hljs-number">1</span>    <span class="hljs-number">0.567547</span>
   <span class="hljs-number">2</span>   -<span class="hljs-number">0.154148</span>
dtype: float64
</code></pre>
<blockquote>
<h2 id="multiindex&#x7D22;&#x5F15;&#x5BF9;&#x8C61;">MultiIndex&#x7D22;&#x5F15;&#x5BF9;&#x8C61;</h2>
</blockquote>
<ul>
<li><p>&#x6253;&#x5370;&#x8FD9;&#x4E2A;Series&#x7684;&#x7D22;&#x5F15;&#x7C7B;&#x578B;&#xFF0C;&#x663E;&#x793A;&#x662F;MultiIndex</p>
</li>
<li><p>&#x76F4;&#x63A5;&#x5C06;&#x7D22;&#x5F15;&#x6253;&#x5370;&#x51FA;&#x6765;&#xFF0C;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x6709;lavels,&#x548C;labels&#x4E24;&#x4E2A;&#x4FE1;&#x606F;&#x3002;lavels&#x8868;&#x793A;&#x4E24;&#x4E2A;&#x5C42;&#x7EA7;&#x4E2D;&#x5206;&#x522B;&#x6709;&#x90A3;&#x4E9B;&#x6807;&#x7B7E;&#xFF0C;labels&#x662F;&#x6BCF;&#x4E2A;&#x4F4D;&#x7F6E;&#x5206;&#x522B;&#x662F;&#x4EC0;&#x4E48;&#x6807;&#x7B7E;&#x3002;</p>
</li>
</ul>
<p>&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-python">print(type(ser_obj.index))
print(ser_obj.index)
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python">&lt;class &apos;pandas.indexes.multi.MultiIndex&apos;&gt;
MultiIndex(levels=[[&apos;a&apos;, &apos;b&apos;, &apos;c&apos;, &apos;d&apos;], [0, 1, 2]],
           labels=[[0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]])
</code></pre>
<blockquote>
<h2 id="&#x9009;&#x53D6;&#x5B50;&#x96C6;">&#x9009;&#x53D6;&#x5B50;&#x96C6;</h2>
</blockquote>
<ul>
<li><p>&#x6839;&#x636E;&#x7D22;&#x5F15;&#x83B7;&#x53D6;&#x6570;&#x636E;&#x3002;&#x56E0;&#x4E3A;&#x73B0;&#x5728;&#x6709;&#x4E24;&#x5C42;&#x7D22;&#x5F15;&#xFF0C;&#x5F53;&#x901A;&#x8FC7;&#x5916;&#x5C42;&#x7D22;&#x5F15;&#x83B7;&#x53D6;&#x6570;&#x636E;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x5229;&#x7528;&#x5916;&#x5C42;&#x7D22;&#x5F15;&#x7684;&#x6807;&#x7B7E;&#x6765;&#x83B7;&#x53D6;&#x3002;</p>
</li>
<li><p>&#x5F53;&#x8981;&#x901A;&#x8FC7;&#x5185;&#x5C42;&#x7D22;&#x5F15;&#x83B7;&#x53D6;&#x6570;&#x636E;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5728;list&#x4E2D;&#x4F20;&#x5165;&#x4E24;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;&#x524D;&#x8005;&#x662F;&#x8868;&#x793A;&#x8981;&#x9009;&#x53D6;&#x7684;&#x5916;&#x5C42;&#x7D22;&#x5F15;&#xFF0C;&#x540E;&#x8005;&#x8868;&#x793A;&#x8981;&#x9009;&#x53D6;&#x7684;&#x5185;&#x5C42;&#x7D22;&#x5F15;&#x3002;</p>
</li>
</ul>
<h4 id="1-&#x5916;&#x5C42;&#x9009;&#x53D6;&#xFF1A;">1. &#x5916;&#x5C42;&#x9009;&#x53D6;&#xFF1A;</h4>
<blockquote>
<p>ser_obj[&apos;outer_label&apos;]</p>
</blockquote>
<p>&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x5916;&#x5C42;&#x9009;&#x53D6;</span>
print(ser_obj[<span class="hljs-string">&apos;c&apos;</span>])
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-number">0</span>   -<span class="hljs-number">1.362096</span>
<span class="hljs-number">1</span>    <span class="hljs-number">1.558091</span>
<span class="hljs-number">2</span>   -<span class="hljs-number">0.452313</span>
dtype: float64
</code></pre>
<h4 id="2-&#x5185;&#x5C42;&#x9009;&#x53D6;&#xFF1A;">2. &#x5185;&#x5C42;&#x9009;&#x53D6;&#xFF1A;</h4>
<blockquote>
<p>ser_obj[:, &apos;inner_label&apos;]</p>
</blockquote>
<p>&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x5185;&#x5C42;&#x9009;&#x53D6;</span>
print(ser_obj[:, <span class="hljs-number">2</span>])
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python">a    <span class="hljs-number">0.826662</span>
b    <span class="hljs-number">0.015426</span>
c   -<span class="hljs-number">0.452313</span>
d   -<span class="hljs-number">0.051063</span>
dtype: float64
</code></pre>
<p><strong>&#x5E38;&#x7528;&#x4E8E;&#x5206;&#x7EC4;&#x64CD;&#x4F5C;&#x3001;&#x900F;&#x89C6;&#x8868;&#x7684;&#x751F;&#x6210;&#x7B49;</strong></p>
<blockquote>
<h2 id="&#x4EA4;&#x6362;&#x5206;&#x5C42;&#x987A;&#x5E8F;">&#x4EA4;&#x6362;&#x5206;&#x5C42;&#x987A;&#x5E8F;</h2>
</blockquote>
<h4 id="1-swaplevel">1. swaplevel()</h4>
<blockquote>
<p>.swaplevel( )&#x4EA4;&#x6362;&#x5185;&#x5C42;&#x4E0E;&#x5916;&#x5C42;&#x7D22;&#x5F15;&#x3002;</p>
</blockquote>
<p>&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-python">print(ser_obj.swaplevel())
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-number">0</span>  a    <span class="hljs-number">0.099174</span>
<span class="hljs-number">1</span>  a   -<span class="hljs-number">0.310414</span>
<span class="hljs-number">2</span>  a   -<span class="hljs-number">0.558047</span>
<span class="hljs-number">0</span>  b    <span class="hljs-number">1.742445</span>
<span class="hljs-number">1</span>  b    <span class="hljs-number">1.152924</span>
<span class="hljs-number">2</span>  b   -<span class="hljs-number">0.725332</span>
<span class="hljs-number">0</span>  c   -<span class="hljs-number">0.150638</span>
<span class="hljs-number">1</span>  c    <span class="hljs-number">0.251660</span>
<span class="hljs-number">2</span>  c    <span class="hljs-number">0.063387</span>
<span class="hljs-number">0</span>  d    <span class="hljs-number">1.080605</span>
<span class="hljs-number">1</span>  d    <span class="hljs-number">0.567547</span>
<span class="hljs-number">2</span>  d   -<span class="hljs-number">0.154148</span>
dtype: float64
</code></pre>
<blockquote>
<h2 id="&#x4EA4;&#x6362;&#x5E76;&#x6392;&#x5E8F;&#x5206;&#x5C42;">&#x4EA4;&#x6362;&#x5E76;&#x6392;&#x5E8F;&#x5206;&#x5C42;</h2>
</blockquote>
<h4 id="sortlevel">sortlevel()</h4>
<blockquote>
<p>.sortlevel( )&#x5148;&#x5BF9;&#x5916;&#x5C42;&#x7D22;&#x5F15;&#x8FDB;&#x884C;&#x6392;&#x5E8F;&#xFF0C;&#x518D;&#x5BF9;&#x5185;&#x5C42;&#x7D22;&#x5F15;&#x8FDB;&#x884C;&#x6392;&#x5E8F;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F;&#x5347;&#x5E8F;&#x3002;</p>
</blockquote>
<p>&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x4EA4;&#x6362;&#x5E76;&#x6392;&#x5E8F;&#x5206;&#x5C42;</span>
print(ser_obj.swaplevel().sortlevel())
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-number">0</span>  a    <span class="hljs-number">0.099174</span>
   b    <span class="hljs-number">1.742445</span>
   c   -<span class="hljs-number">0.150638</span>
   d    <span class="hljs-number">1.080605</span>
<span class="hljs-number">1</span>  a   -<span class="hljs-number">0.310414</span>
   b    <span class="hljs-number">1.152924</span>
   c    <span class="hljs-number">0.251660</span>
   d    <span class="hljs-number">0.567547</span>
<span class="hljs-number">2</span>  a   -<span class="hljs-number">0.558047</span>
   b   -<span class="hljs-number">0.725332</span>
   c    <span class="hljs-number">0.063387</span>
   d   -<span class="hljs-number">0.154148</span>
dtype: float64
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; BigCat all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x300C;Revision Time:
2017-03-14 01:33:03&#x300D;
</span></footer>
                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../file/part03/3.4.html" class="navigation navigation-prev " aria-label="Previous page: Pandas的函数应用"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../file/part03/3.6.html" class="navigation navigation-next " aria-label="Next page: Pandas统计计算和描述"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"disqus":{"shortName":"gitbookuse"},"github":{"url":"https://github.com/dododream"},"search-pro":{"cutWordLib":"nodejieba","defineWord":["gitbook-use"]},"sharing":{"weibo":true,"facebook":true,"twitter":true,"google":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"tbfed-pagefooter":{"copyright":"Copyright © BigCat","modify_label":"「Revision Time:","modify_format":"YYYY-MM-DD HH:mm:ss」"},"baidu":{"token":"ff100361cdce95dd4c8fb96b4009f7bc"},"sitemap":{"hostname":"http://www.treenewbee.top"},"donate":{"wechat":"http://weixin.png","alipay":"http://alipay.png","title":"","button":"赏","alipayText":"支付宝打赏","wechatText":"微信打赏"},"edit-link":{"base":"https://github.com/dododream/edit","label":"Edit This Page"},"splitter":{},"toggle-chapters":{},"highlight":{},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book Python数据分析课程讲义 -->
</html>
